package com.ds.infrastructure.hyperspace.common.flow;

import com.ds.infrastructure.hyperspace.common.EndpointProtocolEnum;
import com.ds.infrastructure.hyperspace.common.StateEnum;
import com.ds.infrastructure.hyperspace.common.TargetEndpointStream;

import java.util.Map;

/**
 * @author  Weishaoying
 */
public interface DuplexFlowContext {

    /**
     * Reset context state
     */
    void resetState();

    /**
     * Get refer target endpoint service name
     * @return
     */
    String getServiceName();

    /**
     * Protocol cluster
     * @return
     */
    EndpointProtocolEnum getEndpointProtocol();

    /**
     * Get client ip
     * @return
     */
    String getClientIp();

    /**
     * Route status is true where match some route policies
     * @return
     */
    boolean isRouteMatch();

    /**
     * Change route match status
     * @param routeMatch
     */
    void setRouteMatch(boolean routeMatch);

    /**
     * Set interrupt data
     * @param state
     * @param message
     */
    void setInterruptState(StateEnum state, String message);

    /**
     * Get interrupt state
     * @return
     */
    StateEnum getInterruptState();

    /**
     * Get sharding key type from context
     * @return
     */
    String getShardingKeyType();

    /**
     * Get zone streamId from context
     * @return
     */
    String getZoneId();

    /**
     * Set zone streamId to this context
     * @param zoneId
     */
    void setZoneId(String zoneId);

    /**
     * Get refer zoned stream
     * @return
     */
    Map<String, TargetEndpointStream> getReferTargetEndpointStreamMap();

    /**
     * Get refer stream that zoned
     * @return
     */
    TargetEndpointStream getCurrentReferTargetEndpointStream();

    /**
     * Set refer stream that corresponding zoned
     * @param stream
     */
    void setReferTargetEndpointStream(TargetEndpointStream stream);

    /**
     * Get context header
     * @param headerName
     * @return
     */
    String getContextHeader(String headerName);

    /**
     * Set context header
     * @param headerName
     * @param headerValue
     */
    void setContextHeader(String headerName, String headerValue);

    /**
     * Append data for fault tolerant
     * @param data
     */
    void appendReferData(Object data);

    /**
     * Close this context
     */
    void close();

    /**
     * True while context closed and no longer response
     * @return
     */
    boolean isClosed();

}
